class Solution {
public:
    string convert(string s, int numRows) {
         int length = s.length();
         int r = numRows*2-2;
         string newS;
         int temp;
         int l;
         if(numRows <= 1) newS=s;
         else
         {
         for(int i=0 ;i<numRows;i++)
         {
             int j=i;
             l=0;
             while(j<length)
             {
                 newS.push_back(s[j]);
                 if(i==0 or i==numRows-1)
                 {
                     temp=r;
                 }
                 else
                 {
                     if(l%2==0)
                     {
                         temp = 2*numRows -2*i -2;
                     }
                     else
                     {
                         temp = 2*i;
                     }

                 }
                 j=j+temp;
                 l++;
             }
         }
         }
         return  newS;
    }
};
